package com.easy.goods.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.bean.Category;
import com.easy.goods.mapper.Categorydao;
import com.easy.goods.service.CategoryService;
import com.easy.util.VerifyUtil;
@Service
public class CategoryServiceImpl extends ServiceImpl<Categorydao, Category> implements CategoryService {
@Autowired
//        @Qualifier("categorydao")

    Categorydao categorydao;



    @Override
    public List<Category> getSuperCategoryList() {
        //所有父级分类id=0就是 一级分类
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parentid",0);
        List<Category> list = categorydao.selectList(queryWrapper);
        for(Category item:list) {
        	List children=getCategoryChildrenList(item.getId());
        	item.setChildren(children);
        }
        return list;
    }

	@Override
	public List<Category> getCategoryChildrenList(int parentid) {
		QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parentid",parentid);
        List<Category> list = categorydao.selectList(queryWrapper);
        return list;
	}


    @Override
    //分页
    public List<Category> getCategoryList(IPage page, Category category) {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        if (category!=null){
        if (VerifyUtil.isNotEmpty(category.getDescription())){
            queryWrapper.like("description",category.getDescription());
        }
        if (VerifyUtil.isNotEmpty(category.getName())){
            queryWrapper.like("name",category.getName());
        }
        }
List<Category> list = categorydao.selectList(queryWrapper);
        return list;
    }

    @Override
    public Category getCategoryById(Integer id) {
        return null;
    }


    @Override
    public int addCategory(Category category) {
        return 0;
    }

    @Override
    public int deleteCategory(Integer id) {
        return categorydao.deleteById(id);
    }

    @Override
    public int editCategory(Category category) {
        return 0;
    }

    @Override
    public void updatecateshangxiajia(Integer id) {
        Category category=categorydao.selectById(id);
        System.out.println("----------");
        Integer stutus=category.getIsactive().equals("1")?0:1;
        category.setIsactive(stutus);
        categorydao.updateById(category);
    }

}
